package cn.com.dhc.danlu.business.shopcar.bean;

import cn.com.dhc.danlu.activity.delivery.order.decorate.Visitable;
import cn.com.dhc.danlu.business.shopcar.typefactory.IShopCarTypeFactory;

/**
 * author: 李一方(<a href="mailto:liyifang@danlu.com">liyifang@danlu.com</a>)<br/>
 * version: 1.0.0<br/>
 * since: 2017-03-02 14:22
 *
 * <p>
 * 内容描述区域
 * </p>
 */
public abstract class ShopCarItem extends Visitable<IShopCarTypeFactory> {
    private boolean isEditMode;
    private boolean isEdited;
    // TODO: 2017/3/12 如果 seller 下的所有商品都不选择 则 seller 也不可以购买，需要注意 @lyf
    private boolean isEnable = true;
    private boolean isChecked = true;

    public boolean isEditMode() {
        return isEditMode;
    }

    public void setEditMode(boolean editMode) {
        isEditMode = editMode;
    }

    public boolean isSelected() {
        return isEditMode() ? isEdited() : isChecked() && isEnable();
    }

    /**
     * 设置选中转台
     *
     * @param selected
     *         true - 选中
     */
    public void setSelected(boolean selected) {
        if (isEditMode()) {
            setEdited(selected);
        } else {
            setChecked(isEnable() && selected);
        }
    }

    private boolean isChecked() {
        return isChecked;
    }

    private void setChecked(boolean isChecked) {
        this.isChecked = isChecked;
    }

    private boolean isEdited() {
        return isEdited;
    }

    private void setEdited(boolean isEdited) {
        this.isEdited = isEdited;
    }

    public boolean isEnable() {
        return isEnable;
    }

    public void setEnable(boolean enable) {
        isEnable = enable;
    }
}
